/*
 * @Description:系统基本信息
 * @Author: wangfuwei
 * @Date: 2020-11-30 17:40:08
 * @LastEditors: wangfuwei
 * @LastEditTime: 2021-04-23 21:34:39
 * @FilePath: /horizon-frontend/src/store/modules/app.js
 */
import Vue from "vue";
import { updateTheme, updateColorWeak } from "@/components/SettingDrawer/settingConfig";
import { LANGUAGE, PRIMARY_COLOR, COLOR_WEAK, DEVICE } from "@/store/mutation-types";
import { ACCEPT_LANGUAGE, LS_COLOR, LS_COLOR_WEAK } from "@/core/const";

const app = {
  namespaced: true,
  state: {
    logo: require("@/assets/logo.png"), //系统logo
    copyright: "Copyright © 2020 Horizon", //版权信息
    language: "", //国际化语言
    primaryColor: "#5582F3", //主题色
    colorWeak: false, //色盲模式
    device: "desktop", //设备信息
  },
  mutations: {
    [LANGUAGE]: (state, language) => {
      state.language = language;
      Vue.ls.set(ACCEPT_LANGUAGE, language);
    },
    [PRIMARY_COLOR]: (state, color) => {
      state.primaryColor = color;
      updateTheme(color);
      Vue.ls.set(LS_COLOR, color);
    },
    [COLOR_WEAK]: (state, mode) => {
      state.colorWeak = mode;
      updateColorWeak(mode);
      Vue.ls.set(LS_COLOR_WEAK, mode);
    },
    [DEVICE]: (state, device) => {
      state.device = device;
    },
  },
  actions: {
    setLanguage({ commit }, language) {
      return new Promise(resolve => {
        commit(LANGUAGE, language);

        //todo 存储至用户个性化信息
        resolve();
      });
    },
    setPrimaryColor({ commit }, color) {
      return new Promise(resolve => {
        commit(PRIMARY_COLOR, color);

        //todo 存储至用户个性化信息
        resolve();
      });
    },

    setColorWeak({ commit }, weak) {
      return new Promise(resolve => {
        commit(COLOR_WEAK, weak);

        //todo 存储至用户个性化信息
        resolve();
      });
    },
  },
};

export default app;
